<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>
        .hide{
            display: none;
        }
        .c1{
            position: fixed;
            top:0;
            bottom: 0;
            left:0;
            right: 0;
            background: rgba(0,0,0,.5);
            z-index: 2;
        }
        .c2{
            background-color: white;
            position: fixed;
            width: 400px;
            height: 300px;
            top:50%;
            left: 50%;
            z-index: 3;
            margin-top: -150px;
            margin-left: -200px;
            padding-top: 2%;
            padding-left: 2%;
        }
		#modal p {
			margin-left:80px;
		}
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            检测单创建/执行
        </div>
    </header>
    
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">

            <ul class='aui-list aui-media-list ui-selectee'>
                <li class='aui-list-item  ui-selectee' style='color: black !important;background-color:#d0d0d0 !important;'>
                    <div class='aui-list-item-inner ui-selectee '>
                        <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                            <div class='aui-list-item-label ui-selectee list-tr-title'>记录单号:</div>
                            <div class="aui-list-item-input" >
                                <input type="text" id="recordCode" disabled="true" />
                            </div>
                        </div>
                        <!-- <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                            <div class='aui-list-item-label ui-selectee list-tr-title'>创建日期:</div>
                            <div class="aui-list-item-input" >
                                <input type="text" id="dateTime" disabled="true" />
                            </div>
                        </div> -->
                        <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                            <div class='aui-list-item-label ui-selectee list-tr-title'>产线:</div>
                            <div class="aui-list-item-input">
                                <input type="text" id="workCenterCode" disabled="true" />
                            </div>
                        </div>
                        <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                            <div class='aui-list-item-label ui-selectee list-tr-title'>工单号:</div>
                            <div class="aui-list-item-input">
                                <input type="text" id="workOrderCode" disabled="true" />
                            </div>
                        </div>
                        <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                            <div class='aui-list-item-label ui-selectee list-tr-title'>物料编码:</div>
                            <div class="aui-list-item-input">
                                <input type="text" id="mrlCode" disabled="true" />
                            </div>
                        </div>
                        <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                            <div class='aui-list-item-label ui-selectee list-tr-title'>规格:</div>
                            <div class="aui-list-item-input">
                                <input type="text" id="drawing" disabled="true" />
                            </div>
                        </div>
                        <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                            <div class='aui-list-item-label ui-selectee list-tr-title'>物料名称:</div>
                            <div class="aui-list-item-input">
                                <input type="text" id="mrlName" disabled="true" />
                            </div>
                        </div>
                        <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                            <div class='aui-list-item-label ui-selectee list-tr-title'>追溯类型:</div>
                            <div class="aui-list-item-input">
                                <input type="text" id="reviewType" disabled="true" />
                            </div>
                        </div>
                        <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                            <div class='aui-list-item-label ui-selectee list-tr-title'>检测单数量:</div>
                            <div class="aui-list-item-input">
                                <input type="text" id="qty" disabled="true"/>
                            </div>
                        </div>
                        <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                            <div class='aui-list-item-label ui-selectee list-tr-title'>备注:</div>
                            <div class="aui-list-item-input">
                                <input type="text" id="remark" disabled="true" />
                            </div>
                        </div>
                    </div>
                </li>
            </ul>

<!--弹出表单 批次件：检测数量、序列件：序列号  -->
<div id="shade" class="c1 hide"></div>
<div id="modal" class="c2 hide">
    <p style="margin-left: 10px;font-size: 1rem;font-weight: 500;color: #212121;text-align: center;">创建检测单</p> 
    <ul class="aui-list aui-form-list" style="margin-top: 1%;">
        <li class="aui-list-item" id="chkmrlQtyItem">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label">检测数量</div>
                <div class="aui-list-item-input">
                    <input type="text" placeholder="检测数量" id="chkmrlQty" value="" onclick="getIdSelector();" />
                </div>
                
            </div>
        </li>
        <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label">业务时间</div>
                <div class="aui-list-item-input">
                    <input readonly class="form-control" type="text" id="dateTimeBus" placeholder="请选择">
                </div>
            </div>
        </li>
        <li class="aui-list-item" id="produbarCodeItem">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label">产品序列号</div>
                <div class="aui-list-item-input">
                    <input type="text" placeholder="请扫描序列号" id="produbarCode" value="" onclick="getIdSelector();" />
                </div>
                <i class="aui-input-addon aui-iconfont aui-icon-scan " style="padding-right:20px;font-size: 1.6rem"
                    onclick="doScan();"></i>
            </div>
        </li>
    </ul>
    <footer class="aui-bar aui-bar-tab" style="position: absolute;">
            <!-- <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i> -->
            <div class="aui-btn aui-btn-info" style="width:30%;margin-left:2%;" onclick="Hide()">取消</div>
            <div class="aui-btn aui-btn-info" style="width:30%;margin-left:2%;" onclick="xlj()">确定</div>
    </footer>
</div>

            <!-- <ul class="aui-list aui-form-list">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">检测类型 </div>
                        <div class="aui-list-item-input">
                            <label><input class="aui-radio" type="radio" value="SMJ" name="operateType" checked>首末检</label>
                            <label><input class="aui-radio" type="radio" value="XJ" name="operateType">巡检</label>
                        </div>
                    </div>
                </li>
                <li class="aui-list-item list-qty" >
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">检测数量</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="输入检测数量" id="chkQty" value=""/>
                        </div>
                    </div>
                </li>
                <li class="aui-list-item list-num" >
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">序列号</div>
                        <div class="aui-list-item-inner">
                            <input type="text" class="aui-input" placeholder="请扫描序列号" id="serialNo" value="" onclick="getIdSelector();" />
                            <i class="aui-input-addon aui-iconfont aui-icon-scan " style="padding-right:10px;font-size: 1.6rem" onclick="doScan();"></i>
                        </div>
                    </div>
                </li>
            </ul> -->
        <div style="padding-top:2%;"></div>

        <ul class="ui-selectee" id="tbodyHtml">

        </ul>
        <p></p>
        <p></p>
    </div>
    <div style="height:60px;"></div>
    <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="doSave()">创建检测单</div>

    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/jdate.min.js"></script>
<script type="text/javascript" src="../script/clickThrottle.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var workCenterCode = ""; //产线编码
    var workOrderCode = "";//工单号
    var mrlCode = ""; //物料编码
    var mrlName = ""; //物料名称
    var mrlId = ""
    var drawing = "";
    var lotCode = "";
    var mrlGid = ""

    var chkBillType = "";//检测单类型
    var chkTemplateCode = ""//检测模板
    var recordId = ""//记录表主键

    var SMJFlag = 0;
    var MJFlag = 0

    var chkTypeCode = ""//检测类型

    var remark = "" // 备注

    let currentDate = new Date();
    let year = currentDate.getFullYear(); // 获取当前年份
    let month = (currentDate.getMonth() + 1) < 10 ? "0" + (currentDate.getMonth() + 1) : (currentDate.getMonth() + 1); // 获取当前月份，注意月份从0开始，所以要加1
    let day = currentDate.getDate() < 10 ? "0" + currentDate.getDate() : currentDate.getDate(); // 获取当前日期
    let hours = currentDate.getHours() < 10 ? "0" + currentDate.getHours() : currentDate.getHours(); // 获取当前小时
    let minutes = currentDate.getMinutes() < 10 ? "0" + currentDate.getMinutes() : currentDate.getMinutes(); // 获取当前分钟
    let seconds = currentDate.getSeconds() < 10 ? "0" + currentDate.getSeconds() : currentDate.getSeconds(); // 获取当前秒

    let time = year + '-' + month + '-' + day +' '+hours+':'+minutes+':'+seconds

    //初始化查询
    apiready = function () {
        recordCode = api.pageParam.recordCode
        $("#recordCode").val(recordCode);

        // 业务日期
        $("#dateTimeBus").val(time);
        //  查询
        search()
        doSearchChkBillDetails()

        new Jdate({
            el: '#dateTimeBus',
            format: 'YYYY-MM-DD hh:mm:ss',
            beginYear: 2000,
            endYear: 2100
        });
    }

    function Show(zsType){
        document.getElementById('shade').classList.remove('hide');
        document.getElementById('modal').classList.remove('hide');
        zsType = $("#reviewType").val()
        if(zsType=="序列件"){
            $("#chkmrlQtyItem").css('display', 'none');
            $("#produbarCodeItem").css('display', 'block');
            api.setFocus({
                inputId: 'produbarCode',
                focus: true
            })
            idSelector = 'produbarCode'
        }else{
            $("#chkmrlQtyItem").css('display', 'block');
            $("#produbarCodeItem").css('display', 'none');
            api.setFocus({
                inputId: 'chkmrlQty',
                focus: true
            })
        }
        $("#chkmrlQty").val("");
        $("#produbarCode").val("");
    }
    function Hide(){
        $("#chkmrlQty").val("");
        $("#produbarCode").val("");
        document.getElementById('shade').classList.add('hide');
        document.getElementById('modal').classList.add('hide');
    }

    //获取检测模板
    function getChkTemplateCode() {
        var mrlCodeSearch = $("#mrlCode").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getChkTemplateCode";
        var data = {
            values: {
                chkBillType: chkBillType,//检测单类型
                mrlCode:mrlCodeSearch,
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);
                    chkTemplateCode = list[0].code
                    //console.log(chkTemplateCode)
                    /* $("#chkTemplateName").val(list[0].name);
                    $("#chkTypeName").val(list[0].chkTypeName); */
                    Show(reviewType);
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }
    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    function search() {
        var recordCode = $("#recordCode").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/searchChkRecord";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                recordCode: recordCode,
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    var map = myobj.list;
                    for (var key in map){
                        $("#workCenterCode").val(map[key].workCenterCode);
                        $("#workOrderCode").val(map[key].workOrderCode);
                        $("#mrlCode").val(map[key].mrlCode);
                        $("#mrlName").val(map[key].mrlName);
                        $("#drawing").val(map[key].drawing);
                        $("#qty").val(map[key].qty);
                        $("#dateTime").val(map[key].create_date);
                        $("#reviewType").val(map[key].reviewType);
                        $("#remark").val(map[key].remark);
                        lotCode = map[key].lotCode;
                        recordId = map[key].recordId;
                        mrlId =  map[key].mrlId;
                    }               
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });

                }
            }
        });
    }

    //查询检测记录下检测单
    function doSearchChkBillDetails() {
        var recordCode = $("#recordCode").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/searchChkBillList";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                recordCode: recordCode,
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    list = myobj.list;
                    setTable(list)
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });

                }
            }
        });
    } 

    function setTable(list) {
        var html = "";
        for (var i = 0; i < list.length; i++) {
            if(list[i].chkTypeCode == "SMJ"){
                SMJFlag += 1
            }
            if(list[i].chkTypeCode == "MJ"){
                MJFlag += 1
            }
            html += "<div style='padding-top:4%;'></div>";
            html += "<li class='sortable ui-selectee ui-sortable' >";
            html += "<ul class='aui-list aui-media-list ui-selectee'>";
            html += "<li class='aui-list-item  ui-selectee' style='color: black !important;background-color: #addbef !important;'>";
            html += "<div class='aui-media-list-item-inner ui-selectee ' >";
            html += "<div class='aui-list-item-inner ui-selectee '>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>检测单号:</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].chkBillCode + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>检测类型:</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].chkTypeName + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>业务时间:</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].dateTime + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title' style='width:43%'>检测结果:</div>";
            html += "<div class='aui-list-item-inner ui-selectee' style='position: relative'>" + list[i].chkResultName + "</div>";
            html += "<div class='aui-list-item-right aui-btn ui-selectee' style='background-color:#FA8072;margin-right:80px' onclick='deleteTab(\"" + list[i].chkBillCode + "\");'>删除</div>";
            html += "<div class='aui-list-item-right aui-btn ui-selectee' style='position:absolute;algin:right;right:0' onclick='deal(\"" + list[i].chkBillCode + "\",\"" + list[i].chkBillDetailsId + "\");'>处理</div>";
            html += "</div>";

            html += "</div>";
            html += "</li>";
            html += "</ul>";
            html += "</li>";
        }
        $api.html($api.byId("tbodyHtml"), html);
    };

    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {
     
            if (idSelector == 'produbarCode') {
                //序列号
                $("#produbarCode").val(ret);
                getMrlName(ret)
                $("#tableDiv").css('display', 'none');
            }
        });
    }

     //获取
     function getMrlName(serialNo) {
        var workOrderCode =  $("#workOrderCode").val()
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getMrlName";
        var data = {
            values: {
                serialNo: serialNo,
                workOrderCode:workOrderCode,
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                if (map.code == "0") {
                    mrlCode = $("#mrlCode").val();

                    if(mrlCode!=map.mrlCode){
                        api.toast({
                            msg: "物料不一致",
                            duration: 3000
                        });
                    }
                    mrlGid=map.mrlGid
                    doSubmit(serialNo)
                } else {
                    api.toast({
                        msg: map.message,
                        duration: 6000
                    });
                }
          
            }
        });
    }
     //序列号扫描回车
     $("#produbarCode").on('keypress', function (e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            if (!clickThrottle()) {
                return;
            }
            $("#produbarCode").val(tm);
            getMrlName(tm)
            //获取检测模板
            $("#tableDiv").css('display', 'none');
        }
    });
    //处理
    function deal(chkBillCode,chkBillDetailsId) {
        var chkBillCode = chkBillCode
        var chkBillDetailsId = chkBillDetailsId
       
        api.openWin({
            name: 'qcmChkBillDeal',
            url: 'qcmChkBillDeal.html',
            pageParam: {
                chkBillDetailsId: chkBillDetailsId,
                chkBillCode: chkBillCode,
                name: "qcmChkBillCreateOrDeal",
            }
        });
    }

    //创建
    function doSave() {
        var dialogBox = api.require('dialogBox');
        dialogBox.evaluation({
            styles: {
                bg: '#fff',
                w: 300,
                title: {
                    marginT: 20,
                    size: 15,
                    color: '#000',
                    bold: true
                },
                content: {
                    marginT: 20,
                    color: '#111',
                    size: 12
                },
                buttons: [{
                    marginB: 0,
                    marginL: 0,
                    w: 300,
                    h: 35,
                    bg: '#fff',
                    color: '#007FFF',
                    size: 12
                }, {
                    marginB: 0,
                    marginL: 0,
                    w: 300,
                    h: 35,
                    bg: '#fff',
                    color: '#007FFF',
                    size: 12
                }, {
                    marginB: 0,
                    marginL: 0,
                    w: 300,
                    h: 35,
                    bg: '#fff',
                    color: '#007FFF',
                    size: 12
                }]
            },
            tapClose: true,//是否点击遮罩层关闭该对话框
            texts: {
                title: '选择',
                content: '请选择检测单类型',
                buttons: [{
                    text: '首件检测'
                },{
                    text: '末件检测'
                },{
                    text: '巡检'
                }]
            }
        }, function (ret, err) {
            if (ret) {
                if (ret.index == 0) {
                    //首末件检测
                    chkBillType ='SMJ';
                    /* if(SMJFlag > 0){
                        dialogBox.close();
                        api.toast({
                            msg: '只可进行一次首件检测',
                            duration: 3000
                        });
                        return;
                    } */
                } else if (ret.index == 1) {
                    //巡检
                    chkBillType ='MJ';
                    /* if(MJFlag > 0){
                        dialogBox.close();
                        api.toast({
                            msg: '只可进行一次末件检测',
                            duration: 3000
                        });
                        return;
                    } */
                }else if (ret.index == 2) {
                    //巡检
                    chkBillType ='XJ';
                }
                getChkTemplateCode()
                var reviewType = $("#reviewType").val()

                dialogBox.close();
                Show(reviewType);//打开录入检测数量和产品序列号表单
            } else {
                api.alert({
                    msg: JSON.stringify(err)
                });
            }
        });
    }
    function xlj() {
        var reviewType = $("#reviewType").val()
        var text = $("#chkmrlQty").val();
        if(reviewType=="序列件"){
            var text = $("#produbarCode").val();
            //去掉码中回车符
            text = text.replace(/[\r\n]/g,"");
            if(text == ""){
                api.toast({
                    msg: '序列号不可以为空',
                    duration: 3000
                });
            }else{
                getMrlName(text)
                //序列件 序列号
            }
        }else if(reviewType=="批次件"){
            var text = $("#chkmrlQty").val();
            if(text == ""){
                api.toast({
                    msg: '检测数量不可以为空',
                    duration: 3000
                });
            }else{
                save(text)
                //批次件 检测数量
            } 
        }
    }
   //保存按钮
   function doSubmit(serialNo) {
        var mrlCode = $("#mrlCode").val();

        var mrlName = $("#mrlName").val();
        // 业务日期
        var dateTimeBus = $("#dateTimeBus").val();
        //序列号
        var serialNo = serialNo;
        //产线
        var workCenterCode = $("#workCenterCode").val()

        if (serialNo == "" || serialNo == null || serialNo == undefined) {
            api.toast({
                msg: '序列号不可以为空',
                duration: 3000
            });
            return;
        }
        // 业务日期非空校验
        if (dateTimeBus == "" || dateTimeBus == null || dateTimeBus == undefined) {
            api.toast({
                msg: '请选择业务日期',
                duration: 3000
            });
            return;
        }
        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/qcmChkBillCreateSave";
        var data = {
            values: {
                un: un,
                chkBillTypeNum: '2', //检测单类型
                chkTemplateCode: chkTemplateCode, //检测模板编码
                serialNo: serialNo, //序列号
                qty: '1', //检测数量
                workOrderCode: workCenterCode, //产线
                mrlCode: mrlCode,//物料编码
                mrlName: mrlName,//物料名称
                mrlGid: mrlGid,//物料ID
                recordId:recordId,//记录单主键
                dateTimeBus: dateTimeBus,//业务日期
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 'S') {

                    api.hideProgress();
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });
                    search()
                    doSearchChkBillDetails()
                    $("#produbarCode").val();//？
                    Hide();
                } else {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    Hide();
                }
            } else {
                api.hideProgress();
            }
        });
    }
     //保存按钮
     function save(qty) {
        //检测数量
        var qty = qty;

        var mrlCode = $("#mrlCode").val();

        var mrlName = $("#mrlName").val();

        var dateTimeBus = $("#dateTimeBus").val();
        //工单号
        var workOrderCode = $("#workOrderCode").val()
        //数量非空校验
        if (qty == "" || qty == null || qty == undefined) {
            api.toast({
                msg: '请录入检测数量',
                duration: 3000
            });
            return;
        } else {
            if (parseFloat(qty) <= 0) {
                api.toast({
                    msg: '检测数量必须大于0',
                    duration: 3000
                });
                return;
            }
        }
        // 业务日期非空校验
        if (dateTimeBus == "" || dateTimeBus == null || dateTimeBus == undefined) {
            api.toast({
                msg: '请选择业务日期',
                duration: 3000
            });
            return;
        }

        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/qcmChkBillCreateSave";
        var data = {
            values: {
                chkBillTypeNum: '2',
                chkTemplateCode: chkTemplateCode, //检测模板编码
                lotCode: lotCode, // 批次号
                mrlCode: mrlCode,//物料编码
                mrlName: mrlName,//物料名称
                mrlGid: mrlId,//物料ID
                qty: qty, //检测数量
                workOrderCode: workOrderCode, //工单号
                recordId:recordId,//记录单主键
                dateTimeBus: dateTimeBus,//业务日期
                remark: remark,// 备注
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 'S') {
                    api.hideProgress();
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });

                    search()
                    doSearchChkBillDetails()
                    $("#chkmrlQty").val();
                    Hide();
                } else {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    Hide();
                }
            } else {
                api.hideProgress();
            }
        });
    }
      //删除
      function deleteTab(chkBillCode) {
        api.showProgress({
            title: '删除中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/deleteChkBillCreate";
        var data = {
            values: {
                chkBillCode: chkBillCode,
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                if (map.code == "0") {
                    api.hideProgress();
                    api.toast({
                        msg: "删除成功",
                        duration: 3000
                    });
                    search()
                    doSearchChkBillDetails()
                } else {
                    api.hideProgress();
                    api.toast({
                        msg: map.message,
                        duration: 6000
                    });
                }

            }else{
                api.hideProgress();
            }
        });
    }
    //返回按钮
    function closeWin() {
        api.closeWin({});
    }

</script>


</html>